package com.eco.fanliapp.controller.app;

import cn.jiguang.common.utils.StringUtils;
import com.eco.fanliapp.common.base.AuthController;
import com.eco.fanliapp.common.base.BaseController;
import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.dao.AppFeedBackMapper;
import com.eco.fanliapp.entity.AppFeedBack;
import com.eco.fanliapp.entity.AppUser;
import com.eco.fanliapp.entity.LoginSwitch;
import com.eco.fanliapp.service.IAppFeedBackService;
import com.eco.fanliapp.utils.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/feedback")
public class FeedBackController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(FeedBackController.class);

    @Autowired
    private IAppFeedBackService appFeedBackService;

    @SuppressWarnings("deprecation")
    @RequestMapping("/getopinion")
    @ResponseBody
    private ServerResponse<String> getOpinion(String user_id, String content_feedback, String feedbackImg) {
        if (StringUtils.isEmpty(String.valueOf(user_id)) || StringUtils.isEmpty(content_feedback)) {
            return ServerResponse.createByErrorMessage("请检查你所填写信息是否有误");
        }
        AppFeedBack app = new AppFeedBack();
        app.setUserId(Long.valueOf(user_id));
        app.setContentFeedback(content_feedback);
        app.setFeedbackImg(feedbackImg);
        Long createtime = System.currentTimeMillis();
        app.setCreateTime(createtime);
        int i = appFeedBackService.insertAppFeedBack(app);
        if (i > 0) {
            return ServerResponse.createBySuccessMessage("反馈提交成功");
        }
        return ServerResponse.createByErrorMessage("反馈提交失败");
    }

    @GetMapping("/getopinionList")
    @ResponseBody
    public ServerResponse getopinionList(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "20") Integer pageSize) {

        AppUser appUser = getAppUser();
        if (null == appUser) {
            return ServerResponse.createByErrorCodeMessage(301, "Token不正确");
        }
        //查询用户反馈列表
        return appFeedBackService.getopinionList(appUser, pageNum, pageSize);
    }

}






